home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / l-z < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  1.8 KB  |  75 lines

  1. #!/bin/ksh
  2. # @(#) l-z.ksh 1.1 94/08/04
  3. # 92/09/05 john@armory.com
  4. # 92/11/05 added ability to read filenames from stdin
  5. # 93/12/09 Use xargs for command line args too.
  6. # 94/06/21 Added help.
  7. # 94/08/04 Added r & I opts.  Pass other options to l.
  8. # 94/10/06 Added S option.
  9. # 95/08/03 Added t option.
  10.  
  11. # Make sure the script is run by ksh.  It can be done this way rather than
  12. # making the script a #! script so that if invoked by ksh, it can fork to run
  13. # this and pass more args than can be passed by exec.
  14. #[ -z "$SECONDS" ] && exec ksh -c "$0" "$@"
  15.  
  16. name=${0##*/}
  17. Usage="Usage: $name [-hirt] [l-options] [filename ...]"
  18. typeset -i ReadInput=0
  19.  
  20. while getopts :hIrACFLRabcdfignopqstuS opt; do
  21.     case $opt in
  22.     h)
  23.     echo \
  24. "$name: list files sorted by file size, smallest first.
  25. $Usage
  26. If no filenames are given, the files in the current directory are listed.
  27. Options:
  28. -h: Print this help.
  29. -I: Read input for filenames.
  30. -r: Reverse order of sort (list largest files first).
  31. -t: Print only as many filenames as will fit on the screen.
  32. -S: Print filename only.
  33. Any other - options are passed to l(C)."
  34.     exit 0
  35.     ;;
  36.     I)
  37.     ReadInput=1;;
  38.     r)
  39.     SortArgs=-r;;
  40.     S)
  41.     CutCmd='| awk "{ print \$NF; }"'
  42.     ;;
  43.     t)
  44.     HeadCmd='| head -$((${LINES:-`tput lines`}-2))'
  45.     ;;
  46.     +?)
  47.     print -u2 "$name: options should not be preceded by a '+'."
  48.     exit 1
  49.     ;;
  50.     :) 
  51.     print -r -u2 -- \
  52.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  53.     exit 1
  54.     ;;
  55.     ?)  
  56.     lArgs="$lArgs$opt"
  57.     ;;
  58.     esac
  59. done
  60.  
  61. # remove args that were options
  62. let OPTIND=OPTIND-1
  63. shift $OPTIND
  64.  
  65. [ -n "$lArgs" ] && lArgs=-$lArgs
  66.  
  67. if ((ReadInput)); then
  68.     xargs l $lArgs --
  69. else
  70.     # Might have been passed more args than can be passed to exec
  71.     for arg; do
  72.     print -r "$arg"
  73.     done | xargs l $lArgs --
  74. fi | eval sort +4 -5 -n $SortArgs $CutCmd $HeadCmd
  75.